import csv
from datetime import datetime

import matplotlib.pyplot as plt

filename = 'resouce/sitka_weather_2014.csv'
with open(filename) as f:
    reader = csv.reader(f)
    header_row = next(reader)
    # 是一个Python中常用的内置函数，用于遍历可迭代对象，并返回索引和对应的元素。
    for index, column_header in enumerate(header_row):
        print(index,column_header)

    highs = []
    dates = []
    lows = []
    for row in reader:
        highs.append(row[1])
        dates.append(datetime.strptime(row[0],"%Y-%m-%d"))
        lows.append(row[5])
    print(highs)

fig = plt.figure(dpi=128,figsize=(10,6))
plt.plot(dates, highs, c='red', alpha=0.5)
plt.plot(dates, lows, c='blue',alpha=0.5)
plt.title("Daily high temperatures -2014", fontsize=24)
plt.xlabel('',fontsize=16)
# 绘制斜标签的日期
fig.autofmt_xdate()
plt.ylabel("Temperature(F)",fontsize=16)
plt.tick_params(axis='both',which='major',labelsize=16)
plt.show()